{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 传统滴水算法-字符分割\n",
    "\n",
    "![classical-big-fall-truth-table-0410.jpg](./image/classical-big-fall-truth-table-0410.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 概要\n",
    "本篇介绍的传统滴水算法，字符分割部分，完全遵循了原文作者在论文中描述的分割逻辑．\n",
    "**Segmentation of Numeric Strings**　G. Congedo, G. Dimauro, S . Impedovo, G. Pirlo, 毫不夸张的说，这篇教程是目前国内外，介绍传统滴水算法，最通俗易懂跟完备的教程．阿凯在搜索这方面的资料的时候大费周章，基本上找不到博客跟详细的参考资料，所以只能去啃论文．其实看论文有时候也是最高效的．\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 滴水算法介绍\n",
    "\n",
    "滴水算法，如其名，算法参考了雨滴的智慧，黑色区域如同空旷的天空，连在一起的字符就像连在一起的两个房屋．　水滴从天空中掉落，顺着缝隙向下流淌，如果他们遇到了困难不能继续下落，就冲破禁锢，水滴石穿，打开缺口向下渗透，直至滑落出画面．　整个过程形成的轨迹，就是两个字符之间的分割线．不同于我们之前介绍的柱状图分割法滴水算法的分割线可以非常灵活．\n",
    "\n",
    "![u=888408617,1697447782&fm=27&gp=0.jpg](./image/u=888408617,1697447782&fm=27&gp=0.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 读入图片并进行二值化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2\n",
    "import numpy as np\n",
    "from matplotlib import pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "阿凯为大家准备了一些测试样例，是阿凯手写并提取出来的，统一放缩到100x100的尺寸，训练集压缩包也可以在群里下载．\n",
    "当然你也可以自己绘制收集样本. \n",
    "![Screenshot_20180316_040221.png](./image/Screenshot_20180316_040221.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP4AAAD8CAYAAABXXhlaAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAEHNJREFUeJzt3U+onNd9xvHvUymKa4dGUgpCkZxawcJBBBJHl9bGWRg7oa4bYi9M6pCCKC7apMRJA6ncrrI0hDhelICwG0wpsVPFVEKLGFdxoCvFV3VobcmK1bixJaTYJXZSsigV/nUx79DJZO6dd2beP+e85/nARZq58+c3550zzzlnzsxVRGBmZfmtvgsws+6545sVyB3frEDu+GYFcsc3K5A7vlmB3PHNCrRSx5d0l6Tzki5IOtJUUWbWLi27gUfSFuDHwCeBi8DzwGcj4mxz5ZlZG7aucN3fBy5ExE8AJD0J3ANs2PEleZugZe3gwYNLX/fMmTMNVrKxiNC8y6zS8fcAr0+cvgj8wfSFJB0GDq9wP2bJWF9fX/q60tz+2JlVOn4tEXEUOApOfEtb259bqXP7Xb04rLK4dwm4fuL03uo8M0vcKh3/eWC/pH2StgH3AyeaKcusHRGx4U8Kuqpt6aF+RFyV9BfAM8AW4O8i4qXGKjOz1iz9dt5Sd+Y5vvUslWRf1CJz/7ZX9a0hTT4ZU1o5bkuunXcV04951ePsLbtmBXLid6zPt4xSHA2UmN5NmGy3ZY6rE9+sQE78jqSQbE3PE1eRQnsMxbgtFzmeTnyzAjnxW5Zyss2qrclRQMqPfYgigrW1tVqXdeKbFciJb41xwufDiW9WICd+S3JNv2VW/nN9rKtYZS0khfZy4psVyB3frEAe6jcshWFckzbbHDK0x7qRpjc6jW+vz/Zz4psVyIk/JcUUS2GBLcV2aUvbW5lTaEsnvlmBik/8FF59N7JI8qQwb8xdih9bbosT36xAx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f+NoikTwFvRMSZvmupaSvwMeCbEXEzo23bvzasT6htdwD3MHqxej9wHXBXr0W1oKuOfwm4fuL03uq8pEh6F6NO/w8R8XR19s8k7a5+vxt4o6/6JtwGfFrSfwJPMhruPwpslzT+/EVKbXwRuBgRp6vTxxi9EKTYtp8AXo2INyPif4GnGbV3qm27lK46/vPA/mpldBujxZITHd13LRp9oudx4FxEfH3iVyeAQ9X/DzGa+/cqIh6KiL0RcQOjtvx+RHwOeA64r7pYErUCRMQV4HVJN1Vn3QmcJcG2ZTTEv0XStdVzYlxrkm27tA4XTe4Gfgz8B/A3fS9uzKjv44yGmv8G/Kj6uZvR3PkU8Arwz8DOvmudqvt24GT1/w8CPwQuAP8IvLvv+ibq/CiwXrXvPwE7Um1b4KvAy8CLwN8D7065bZf58c49swJ5cc+sQO74ZgVyxzcrkDu+WYHc8c0K5I5vViB3fLMCueObFej/AHjafiDmrpODAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "img_path = './toucing_digits_database/2002.png'\n",
    "\n",
    "img = cv2.imread(img_path, cv2.IMREAD_GRAYSCALE)\n",
    "\n",
    "plt.imshow(img, cmap='gray')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实际上我们的素材就是二值化的图片\n",
    "# 为了完整演示， 添加一个二值化的过程\n",
    "_, bin_img = cv2.threshold(img, 128, 255, cv2.THRESH_BINARY)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP4AAAD8CAYAAABXXhlaAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwO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iL0RcQOjtvx+RHwOeA64r7pYErUCRMQV4HVJN1Vn3QmcJcG2ZTTEv0XStdVzYlxrkm27tA4XTe4Gfgz8B/A3fS9uzKjv44yGmv8G/Kj6uZvR3PkU8Arwz8DOvmudqvt24GT1/w8CPwQuAP8IvLvv+ibq/CiwXrXvPwE7Um1b4KvAy8CLwN8D7065bZf58c49swJ5cc+sQO74ZgVyxzcrkDu+WYHc8c0K5I5vViB3fLMCueObFej/AHjafiDmrpODAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.imshow(bin_img, cmap='gray')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(100, 100)\n"
     ]
    }
   ],
   "source": [
    "# 样本的尺寸\n",
    "print(img.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 垂直投影 获取直方图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3Xl03NWV4PHv1b7vi2XJtnYTL3jBscUSwNgsNhCgEzosSQxx4g6BBHqZhEzPZKb79PQkPT0doENIGwgxCZB0IBkIOCTgmDVI3gDLG5atxZasXbb2vd78UVVC2JJVkqrqV7+q+znHR6pSWb9XLvnW1X33vSfGGJRSStlfmNUDUEop5R0a0JVSKkhoQFdKqSChAV0ppYKEBnSllAoSGtCVUipIaEBXSqkgoQFdKa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M4AH8yv9XqgxhjTaowZBn6D8/UP9tfabbLX1qvxzQ4BfTdQ4poNj8I5kfKSxWPyOlft+EngsDHm38Z96SVgk+vzTcCL/h6brxhjvmuMyTPG5ON8Xf9kjLkT2Al83vWwoHrOAMaYJuCkiCx03bUOOEQQv9Y4Sy1lIhLn+ll3P+egfq3Hmey1fQn4sqvbpQzoHFeamT5jTMD/ATYCR4HjwN9bPR4fPcfLcP4ath/4wPVnI86a8g6gCngdSLN6rD56/lcCL7s+LwR2AceAXwPRVo/PB893ObDH9Xr/PyA12F9r4B+AI8AB4OdAdDC+1sBzOOcJhnH+NrZ5stcWEJxdfMeBSpxdQDO+tq4UVUqpIGGHkotSSikPaEBXSqkgoQFdKaWChAZ0pZQKEhrQlVIqSGhAV0qpIKEBXSmlgoQGdKWUChL/H6J2ZMeVhBDNAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def binImgHist(img, bin_width=1, direction=1):\n",
    "    '''\n",
    "        二值化图像在y轴或者x轴方向的投影统计\n",
    "    '''\n",
    "    height, width = img.shape\n",
    "    bins = None\n",
    "    if direction == 0:\n",
    "        # 在y轴方向上统计\n",
    "        bins = int(height / bin_width)\n",
    "    else:\n",
    "        bins = int(width / bin_width)\n",
    "    # 获取非零元素坐标\n",
    "    nonzero_points = np.nonzero(img != 0)\n",
    "    # 获取非零元素坐标中的x坐标集合或者y坐标集合\n",
    "    nonzero_idx_x = nonzero_points[direction]\n",
    "    #返回的统计直方图\n",
    "    hist = np.histogram(np.int64(nonzero_idx_x), bins=bins)[0]\n",
    "    \n",
    "    return hist\n",
    "\n",
    "bin_width = 1\n",
    "hist = binImgHist(bin_img, bin_width=bin_width, direction=1)\n",
    "plt.plot(hist)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 确定水滴的下落起始点"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "接下来，我们需要寻找下落起始点，寻找水滴的下落点的策略有很多。例如从画面的width/2处开始，或者从左侧的峰值或者右侧的峰值滑落。\n",
    "注意，滴水算法跟起始点有密切的关系， 分割效果的好坏，取决于以下两点：\n",
    "\n",
    "* 下落点的位置的选择， 如果选择不好，容易将其中一个字符切开， 例如将0切成1。\n",
    "* 倾斜角度， 倾斜角度小，分割效果就越好。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们采用一个比较简单的方式来获取起始位置， **我们搜索宽度中心附近的几个点，找到最小值的那个坐标。**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "height,width = img.shape\n",
    "mid_x = int(width / 2)\n",
    "search_win = 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "52\n"
     ]
    }
   ],
   "source": [
    "# 在中心区域内检索最小值，决定下落点 x坐标\n",
    "start_x = np.argmin(hist[mid_x - search_win:mid_x + search_win + 1]) + (mid_x - search_win)\n",
    "\n",
    "print(start_x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 制定下落规则"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "这里需要注意的是，我们这片文章中采用的是前景，笔画部分为逻辑1, 作者的论文里面用白色表示背景，黑色表示笔画部分,为远景表示法．\n",
    "所以为了不引起混乱，　我们全局定义一个背景的颜色跟笔的颜色．\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[False, False, False, False, False],\n",
       "       [False, False, False, False, False],\n",
       "       [False, False, False, False, False],\n",
       "       [False, False, False, False, False],\n",
       "       [False, False, False, False, False]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "COLOR_BACK = 0 # 背景颜色\n",
    "COLOR_PEN = 255 # 笔触的颜色\n",
    "\n",
    "# 首先将原来的图片转换成布尔矩阵\n",
    "bool_img = bin_img == COLOR_PEN\n",
    "\n",
    "# 展示部分， 只有0跟1组成的矩阵\n",
    "bool_img[45:50,45:50]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "生成的布尔矩阵与下图的映射关系如下\n",
    "\n",
    "* True -> Black 黑色　笔画的颜色\n",
    "* False -> White 白色　背景色"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "滴水算法，本质上就是通过像素点周边的５个像素点的信息，来判断下一步所要选择的路径．\n",
    "周边像素点，从左边开始，依次编号为 n1,n2,n3,n4,n5, 我们可以通过字典来存储编号与位置的映射关系．\n",
    "\n",
    "```python\n",
    "# 定义邻居坐标 的位置关系\n",
    "NEIGHBOR_IDX = {\n",
    "    1: (-1, 0),\n",
    "    2: (-1, 1),\n",
    "    3: (0, 1),\n",
    "    4: (1, 1),\n",
    "    5: (1, 0)\n",
    "}\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "此截图来自与提出滴水算法的论文\n",
    "\n",
    "接下来，就是制定一些规则来，决定下一个点往哪里走的问题，　下面我给出了完整详细的中文规则说明跟代码演示．\n",
    "![Screenshot_20180316_031919.png](./image/Screenshot_20180316_031919.png)\n",
    "\n",
    "为了避免混淆，我们不使用b跟w表示背景还是字符，改用字符颜色跟背景颜色。\n",
    "总结规则如下：\n",
    "* 优先级1： 全为背景或者全为笔迹 -> n3\n",
    "* 优先级2： n2点为背景，且其他点至少有一个为笔迹的颜色　-> n2\n",
    "* 优先级3: 左下角为笔迹的颜色，正下方为背景色 -> n3\n",
    "* 优先级4: 左下角跟正下方为笔迹的颜色，右下方为背景色 ->n4\n",
    "* 优先级5: 下方全为笔迹颜色，且左边为背景色 -> n5\n",
    "* 优先级6: 除了左边是背景色，其他均为笔迹颜色 ->n1\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "周边一共有5个相关的像素点， 每个像素点有2种状态，所以总共的排列组合方法有$2^5 = 32$种可能的组合方式， 我们按照上述规则，遍历一遍所有的情况与对应的符合哪条处理规则信息。\n",
    "其中**红色圆圈**代表当前的点。 **黑色跟蓝色**代表数字的像素部分(等同于上中的black)， 白色空白部分代表背景(等同于上面的white)。\n",
    "\n",
    "彩笔标出来的数字，代表该情况是由哪个优先级所处理的。\n",
    "\n",
    "![classical-big-fall-truth-table.jpg](./image/classical-big-fall-truth-table-0328.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "不知道大家又没有注意到，在优先级5跟优先级6之间由一个**conditional test 条件测试**\n",
    "\n",
    "原因是，存在一种特殊情况，可以让程序陷入死循环，见下图\n",
    "![classical-big-fall-truth-table-0355－２.jpg](./image/classical-big-fall-truth-table-0355-2.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "所以我们需要检测,该点又没有遍历过，　如果遍历过了，**说明当前存在一个障碍，阻挡水滴下落，我们需要进行渗透处理．**\n",
    "所谓渗透就是向下钻．\n",
    "\n",
    "可以选择在左边渗透或者在右边渗透：\n",
    "![Screenshot_20180316_040617.png](./image/Screenshot_20180316_040617.png)\n",
    "\n",
    "这里我们采用的是下面的那个方案．靠右下钻．\n",
    "```python\n",
    "# 判断点是否重复出现，左右往复平移\n",
    "if next_pt in split_path:\n",
    "    # 已经判断重复，进行渗透\n",
    "    next_pt = (cur_pt[0],cur_pt[1]+1)\n",
    "```\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 定义邻居坐标 的位置关系\n",
    "NEIGHBOR_IDX = {\n",
    "    1: (-1, 0),\n",
    "    2: (-1, 1),\n",
    "    3: (0, 1),\n",
    "    4: (1, 1),\n",
    "    5: (1, 0)\n",
    "}\n",
    "\n",
    "# 根据不同优先级情况，对应的下一个点的位置 n_i\n",
    "CASE_NEXT_POINT = {\n",
    "    1: 3,\n",
    "    2: 2,\n",
    "    3: 3,\n",
    "    4: 4,\n",
    "    5: 5,\n",
    "    6: 1\n",
    "}\n",
    "\n",
    "def is_case_p1(n1, n2, n3, n4, n5):\n",
    "    '''\n",
    "    优先级 ：１\n",
    "    下落方向：　正下方\n",
    "    下落位置： n3\n",
    "    备注：　全为背景或者全为笔迹\n",
    "    '''\n",
    "    if n1 and n2 and n3 and n4 and n5 == True:\n",
    "        # 全为数字部分\n",
    "        return True\n",
    "    elif not(n1) and not(n2) and not(n3) and not(n4) and not(n5) == True:\n",
    "        # 全为背景部分\n",
    "        return True \n",
    "    return False\n",
    "\n",
    "def is_case＿p2(n1, n2, n3, n4, n5):\n",
    "    '''\n",
    "    优先级 ：２\n",
    "    下落方向：　左下方\n",
    "    下落位置： n2\n",
    "    备注：　n2点为背景，且其他点至少有一个为笔迹的颜色\n",
    "    '''\n",
    "    return not(n2) and (n1 or n3 or n4 or n5)\n",
    "\n",
    "def is_case_p3(n1, n2, n3, n4, n5):\n",
    "    '''\n",
    "    优先级 ：3\n",
    "    下落方向：　正下方\n",
    "    下落位置： n３\n",
    "    备注：　左下角为笔迹的颜色，正下方为背景色\n",
    "    '''\n",
    "    return n2 and not(n3)\n",
    "    \n",
    "def is_case_p4(n1, n2, n3, n4, n5):\n",
    "    '''\n",
    "    优先级 ：4\n",
    "    下落方向：右下方\n",
    "    下落位置： n4\n",
    "    备注：　左下角跟正下方为笔迹的颜色，右下方为背景色\n",
    "    '''\n",
    "    return n2 and n3 and not(n4)\n",
    "\n",
    "def is_case_p5(n1, n2, n3, n4, n5):\n",
    "    '''\n",
    "    优先级 ：5\n",
    "    下落方向：右边\n",
    "    下落位置： n5\n",
    "    备注：下方全为笔迹颜色，且左边为背景色\n",
    "    '''\n",
    "    return n2 and n3 and n4 and not(n5)\n",
    "\n",
    "def is_case_p6(n1, n2, n3, n4, n5):\n",
    "    '''\n",
    "    优先级 6\n",
    "    下落方向：左边\n",
    "    下落点：n1\n",
    "    备注　除了左边是背景色，其他均为笔迹颜色\n",
    "    '''\n",
    "    return not(n1) and n2 and n3 and n4 and n5\n",
    "\n",
    "\n",
    "def drop_fall(neighbors):\n",
    "    '''\n",
    "    传统滴水算法　　核心代码\n",
    "    根据优先级实现\n",
    "    neighbors = [n1, n2, n3, n4, n5]\n",
    "    \n",
    "    返回 ：下落点的邻居编号\n",
    "    '''\n",
    "    \n",
    "    for priority in range(1,7):\n",
    "        if eval('is_case_p{}(*neighbors)'.format(priority)):\n",
    "            return CASE_NEXT_POINT[priority]\n",
    "     \n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "def is_legal_pt(img, x, y):\n",
    "    '''\n",
    "    是否为合法的坐标\n",
    "    判断是否超出正常的数值范围\n",
    "    '''\n",
    "    h,w = img.shape\n",
    "    if x < 0 or y < 0 or x >= w or y>= h:\n",
    "        return False\n",
    "    return True\n",
    "\n",
    "def get_neighbors(bool_img, x, y):\n",
    "    '''\n",
    "    给定逻辑图跟坐标， 返回邻居的有序布尔数组\n",
    "    '''\n",
    "    neighbors = []\n",
    "    for n_idx in range(1, 6):\n",
    "        dx,dy = NEIGHBOR_IDX[n_idx]\n",
    "        new_x, new_y = x + dx, y + dy\n",
    "        if not is_legal_pt(bool_img, new_x, new_y):\n",
    "            # 如果坐标不合法 填充背景\n",
    "            neighbors.append(False)\n",
    "        else:\n",
    "            neighbors.append(bool_img[new_y][new_x])\n",
    "    # print(neighbors)\n",
    "    return neighbors"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_split_path(bool_img, start_x):\n",
    "    '''\n",
    "    给出分割路径\n",
    "    '''\n",
    "    height, width = bool_img.shape # 获取图像的高度跟宽度\n",
    "    min_x = 0 # x坐标的左边界\n",
    "    max_x = width - 1 # x坐标的右边界\n",
    "    max_y = height - 1\n",
    "    # 当前的点\n",
    "    cur_pt = (start_x, 0)\n",
    "    # 最近的点\n",
    "    last_pt = cur_pt\n",
    "    # 分割路径\n",
    "    split_path = [cur_pt]\n",
    "    \n",
    "    while cur_pt[1] < max_y:\n",
    "        neighbors = get_neighbors(bool_img, cur_pt[0], cur_pt[1])\n",
    "        n_idx = drop_fall(neighbors)\n",
    "        dx, dy = NEIGHBOR_IDX[n_idx]\n",
    "        next_pt = None\n",
    "        next_x,next_y = cur_pt[0]+dx, cur_pt[1]+dy\n",
    "        if not is_legal_pt(bool_img, next_x, next_y):\n",
    "            # x/y越界 向下渗透\n",
    "            next_pt = (cur_pt[0],cur_pt[1]+1)\n",
    "        else:\n",
    "            next_pt = (next_x, next_y)\n",
    "        # 判断点是否重复出现，左右往复平移\n",
    "        if next_pt in split_path:\n",
    "            # 已经判断重复，进行渗透\n",
    "            next_pt = (cur_pt[0],cur_pt[1]+1)\n",
    "        \n",
    "        cur_pt = next_pt\n",
    "        split_path.append(cur_pt)\n",
    "    return split_path"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 字符分割效果展示"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP4AAAD8CAYAAABXXhlaAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAEM1JREFUeJzt3V+MnNV9xvHvUzsOhaixnUqWY5PiCIvIipQQr1oQuUCQqJRGgQuUEqWSVVH5JlVIGik17VUukaIQLqpIFjRCVRVIHVQjXwRRh0i9clmXqAUbBzc0YMsORIGkykVVi18v5p10MszuvDPz/jnnPc9HWu2+s7Pve+a875nnnDNnZhURmFlZfqvvAphZ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xLisSdbt0jqcNLkT+BHwn8Df9D25MaN8H2fU1fx34IfV152Mxs4ngZeBfwZ29l3WqXLfCpyofv4g8K/AeeAfgXf3Xb6Jcn4UWK/q95+AHanWLfBV4CXgBeDvgXenXLfLfHnlnlmBPLlnViA3fLMCueGbFcgN36xAbvhmBXLDNyuQG75ZgdzwzQr0f4imh/H21ME1AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def view_split_result(img, split_path):\n",
    "    canvas = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)\n",
    "    for (x, y) in split_path:\n",
    "        canvas[y][x] = (0,0,255)\n",
    "    return canvas\n",
    "\n",
    "split_path = get_split_path(bool_img, start_x)\n",
    "canvas = view_split_result(img, split_path)\n",
    "\n",
    "plt.imshow(canvas[:,:,::-1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 总结\n",
    "你也可以换用样本库中的其他训练数据，查看字符分割效果，总之，滴水算法就是这么一个优美的算法．但是也不是没有瑕疵的，　例如它对与倾斜角度较大的字符分割效果就会很差，而且只参考周边5个像素点，容易受噪声干扰．在滴水算法的基础上，后面又诞生了**带惯性的大水滴滴水算法**.感兴趣的同学可以阅读一下附件中的论文　**Inertial and Big Drop Fall Algorithm ** 作者是北京邮电大学的　Xiujuan Wang.\n",
    "建议你尝试阅读下论文，并用Python实现此算法．"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
